package com.qianfeng.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.dto.Page;
import com.qianfeng.entity.Department;
import com.qianfeng.entity.Role;
import com.qianfeng.mapper.DepartmentMapper;
import com.qianfeng.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;

import java.util.List;

@CrossOrigin
@Transactional
@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;


    @Override
    public void addDept(Department department) {
        departmentMapper.addDept(department);
    }

    @Override
    public Page getDeptPage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Department> deptList = departmentMapper.getDeptList();
        Page page = new Page();
        PageInfo<Department> pageInfo = new PageInfo<>(deptList);
        page.setCount(pageInfo.getTotal());
        page.setPages(pageInfo.getPages());
        page.setObj(pageInfo.getList());
        return page;
    }

    @Override
    public List<Department> getDeptList() {
        List<Department> deptList = departmentMapper.getDeptList();
        return deptList;
    }

    @Override
    public List<Department> getDeptByDeptId(Integer deptId) {

        List<Department> deptByDeptId = departmentMapper.getDeptByDeptId(deptId);


        return deptByDeptId;
    }

    @Override
    public void deleteDept(Integer deptId) {
        departmentMapper.deleteDept(deptId);

    }

    @Override
    public void updateDept(Department department) {
        departmentMapper.updateDept(department);
    }
}
